#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;

int longestArithSeqLength(vector<int>& nums) {
    int n = nums.size();
    int ret = 2;
    vector<vector<int>> dp(n, vector<int>(n, 2));
    unordered_map<int, int> hash;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            int sub = 2 * nums[i] - nums[j];
            if (hash.count(sub) && hash[sub] < i)
            {
                dp[i][j] = max(dp[i][j], dp[hash[sub]][i] + 1);
            }
            ret = max(ret, dp[i][j]);
        }
        hash[nums[i]] = i;
    }
    return ret;
}

int numberOfArithmeticSlices(vector<int>& nums) {
    int n = nums.size();
    vector<vector<int>> dp(n, vector<int>(n));
    unordered_map<long long, vector<int>> hash;
    int ret = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            long long sub = (long long)2 * nums[i] - nums[j];
            int a = hash.count(sub);
            if (hash.count(sub) && hash[sub][0] < i)
            {
                int s = hash[sub].size();
                int k = 0;
                while (s--)
                    dp[i][j] += dp[hash[sub][k]][i] + 1, k++;
            }
            ret += dp[i][j];
        }
        hash[nums[i]].push_back(i);
    }
    return ret;
}

int main()
{
	vector<int> v{ 0,2000000000,-294967296 };
    longestArithSeqLength(v);
    numberOfArithmeticSlices(v);

	return 0;
}